import { reqHotSong, reqSongId, reqRecommendSong, reqAlubum, reqSongMenu } from "../../api";

const state = { 
  hotSongList: {},
  songMessage: {},
  recommandSong: {},
  alubumMessage: {},
  songMenu:{},
};

const mutations = {
  //热门歌曲
  GETHOTSONG (state, hotSongList) {
    state.hotSongList = hotSongList;
  },
  //歌曲id
  GETSONGID (state, songMessage) {
    state.songMessage = songMessage;
  },
  //推荐
  GETRECOMMANDSONG (state, recommandSong) {
    state.recommandSong = recommandSong;
  },
  //获取专辑
  GETALUBUM (state, alubumMessage) {
    state.alubumMessage = alubumMessage
  },
  //歌单
  GETSONGMENU (state, songMenu) {
    state.songMenu = songMenu;
  }
};

const actions = {
  //获取热门歌曲
  async getHotSong ({ commit }) {
    let result = await reqHotSong();
    if (result.code == 200) {
      commit('GETHOTSONG', result.rows);
    }
  },
  //获取歌曲信息
  async getSongId ({ commit }, songId) {
    let result = await reqSongId(songId);
    if (result.code == 200) {
      commit('GETSONGID', result.object);
    }
  },
  //获取推荐歌曲
  async getRecommandSong ({ commit }) {
    let result = await reqRecommendSong();
    console.log(result)
    if (result.code == 200) {
      commit('GETRECOMMANDSONG', result.rows);
    }
  },
  //获取专辑歌曲信息
  async getAlubum ({ commit }, Id) {
    let result = await reqAlubum(Id);
    if (result.code == 200) {
      commit('GETALUBUM', result.object);
    }
  },
  //获取歌单信息
  async getSongMenu ({ commit }) {
    let result = await reqSongMenu();
    if (result.code == 200) {
      commit('GETSONGMENU', result.rows);
    }
  },
};


const getters = {};

export default {
  state,
  mutations,
  actions,
  getters,
}

